Skip to content

fix(images): constrain downloads and validate image payloads - #3

Merged
SH20RAJ merged 3 commits into
SopKit:mainfrom
playlikeboy:fix/image-downloader-safety
Nov 27, 2026
Merged

SH20RAJ merged 3 commits into
SopKit:mainfrom
playlikeboy:fix/image-downloader-safety

Conversation

@playlikeboy

Copy link
Copy Markdown

Summary

  • Restrict thumbnail downloads to HTTPS GameMonetize image hosts and reject credentials, custom ports, and unapproved hosts.
  • Resolve redirects manually and revalidate every redirect destination to prevent open-redirect/SSRF pivots.
  • Derive the file extension from an allowlisted response MIME type and verify the image's magic bytes before storing it.
  • Enforce a configurable maximum body size against both Content-Length and streamed bytes.
  • Validate slugs before resolving output paths, write to a temporary file, then atomically rename.
  • Replace the chunked 50-download burst with a bounded worker pool and return downloaded/skipped/failed counts.
  • Add tests for origin restrictions, traversal, MIME/signature mismatch, oversize responses, and redirect validation.

Validation

  • Added Bun tests in tests/download-images.test.ts.
  • The tests have not been executed in this session; the CI workflow in the scraper PR will run bun test once merged.

Compatibility note

The current repository feed uses img.gamemonetize.com thumbnails. The explicit allowlist is intentional; adding another image provider should be a deliberate allowlist change rather than permitting arbitrary URLs.

SH20RAJ commented Nov 27, 2026

Copy link
Copy Markdown

Maintainer review: the new downloader meaningfully reduces risk by constraining origins, validating redirects, checking MIME/signature agreement, limiting streamed bytes, and writing through a temporary file. The bounded worker pool is also a better fit than launching 50 concurrent fetches. I’m checking the regression suite and Actions result before final approval; the current allowlist is deliberately limited to the GameMonetize host used by the feed.

@SH20RAJ SH20RAJ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the updated image downloader and regression suite. The origin allowlist, redirect revalidation, streamed byte cap, MIME/signature checks, safe filename handling, atomic writes, and concurrency bound are all covered by the implementation and tests. GitHub Actions completed successfully: Bun tests and the Next.js production build both passed. Approved.

@SH20RAJ
SH20RAJ merged commit 0c28ce5 into SopKit:main Nov 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants